package com.dayuanit.controller;

import com.dayuanit.controller.request.AddEquipmentPlanParam;
import com.dayuanit.response.ExResponse;
import com.dayuanit.service.EquipmentPlanService;
import com.dayuanit.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "equipmentPlan")
public class EquipmentPlanController {

    @Autowired
    private EquipmentPlanService equipmentPlanService;


    @GetMapping(value = "queryEquipmentPlanList")
    public ExResponse queryEquipmentPlanList(String planName, String equipmentName,
                                             @RequestParam(value = "page") Integer page,
                                             @RequestParam(value = "limit") Integer pageSize) {

        PageInfo pageInfo = equipmentPlanService.queryEquipmentListByPlanNameOrEquipmentName(planName, equipmentName, page, pageSize);
        return ExResponse.buildSuccessList(pageInfo.getData(),pageInfo.getTotalCount());
    }


    @PostMapping(value = "addEquipmentPlan")
    public ExResponse addEquipmentPlan(@RequestBody AddEquipmentPlanParam param) {

        equipmentPlanService.addEquipmentPlan(param);
        return ExResponse.buildSuccessWithoutInfo();
    }

    @PostMapping(value = "deleteEquipmentPlan")
    public ExResponse deleteEquipmentPlan(@RequestBody List<Long> idList) {
        equipmentPlanService.batchRemove(idList);
        return ExResponse.buildSuccessWithoutInfo();
    }
}
